<template>
    <div class="saw">
      <div class="title">
        <div class="back-wrapper"><back></back></div>
        我的已看
      </div>
      <div class="refresh-wrapper" v-show="isRefresh">
        <refresh></refresh>
      </div>
      <loading v-show="isLoading"></loading>
      <div class="content" ref="content">
        <div class="line-block-items">
          <div class="empty" v-show="isEmpty">
            <p class="text">暂无您已看的电影哦</p>
          </div>
          <div class="item" v-for="item in sawList">
            <div class="img-wrapper">
              <img :src="item.posterPicUrl" alt="" width="100%" height="100%">
            </div>
            <div class="text-wrapper">
              <h1 class="name">{{item.name}}</h1>
              <p class="introduction">{{item.nameDesc}}</p>
              <p class="protagonist">{{item.cast}}</p>
            </div>
            <div class="score-wrapper" :class="{evaluation:item.scoreStatus===1}">
              <button class="score" v-if="item.scoreStatus===-1" @click="$router.push({path:'/rating',query:{id:item.id,name:item.name}})">评分</button>
            </div>
          </div>
          <endLine :text="'我是有底线的'" v-show="endFlag&&sawList"></endLine>
        </div>
      </div>
    </div>
</template>

<script>
  import back from '../../../components/back/back'
  import BScroll from 'better-scroll'
  import {getStorage} from "../../../common/js/localStorage";
  import refresh from '../../../components/refresh/refresh'
  import {Toast} from 'mint-ui'
  import loading from '../../../components/loading/loading'
  import endLine from '../../../components/endLine/endLine'
  import global from '../../../common/js/global'
    export default {
        name: "saw",
        components:{
          'back':back,
          'refresh':refresh,
          'loading':loading,
          'endLine':endLine
        },
        data(){
          return{
            evaluation:true,
            sawList:[],
            rows:6,
            endFlag:false,
            isRefresh:false,
            isEmpty:false,
            isLoading:false
          }
        },
        mounted() {
          this._getSawList()
          this.$nextTick(()=>{
            if(!this.scroll){
              // return
              let scroll = new BScroll(this.$refs['content'],{
                click:true,
                pullUpLoad:{
                  threshold:-50
                },
                pullDownRefresh: {
                  threshold: 40,
                  stop: 30
                }
              })
              //下拉回弹刷新停留事件600ms
              scroll.on('pullingDown', () => {
                this.isRefresh = true
                setTimeout(()=>{
                  window.history.go(0)
                  scroll.finishPullDown();
                },600)
              });
              let _this = this
              scroll.on('pullingUp',()=>{

                if(!_this.endFlag){
                  _this.rows+=10;
                  _this._getSawList()
                }
                scroll.refresh()
                scroll.finishPullUp()

              })
            }else {
              this.scroll.refresh();
            }
          })
        },
        methods:{
          _getSawList(){
            this.isLoading = true
            this.$axios(
              {
                method:'post',
                headers:{
                  "Content-Type":"application/json",
                  "MOBILE-DEVICE":'PSD_H5_1_MPS',
                  "JSESSIONID":getStorage('userInfo').JSESSIONID
                },
                url:global.$host+'/member/myHaveSeeList',
                data:{
                  rows:this.rows,
                  offset:5
                }
              }
            ).then((res)=>{
              if(res.status===global.ERR_OK){
                if(res.data.code===0){
                  this.isLoading = false
                  let data = res.data.data
                  this.sawList = data.haveSeeList
                  this.endFlag = data.endFlag
                  if(!this.sawList){
                    this.isEmpty = true
                  }else {
                    this.isEmpty = false
                  }
                }else if(res.data.code===10){
                  this.$router.push('/login')
                }else {
                  Toast(res.data.errorMsg)
                }
              }else {
                Toast('错误代码:'+res.status)
              }

            })
          }
        }
    }
</script>

<style scoped lang="stylus">
  .saw
    position absolute
    height 100%
    width 100%
    background #101011
    user-select none
    overflow hidden
    .title
      position relative
      padding 10px 0
      height 22px
      line-height 22px
      text-align center
      font-size 16px
      color #ffffff
      .back-wrapper
        position absolute
        left 0
        top 10px
        width 36px
        height 22px
    .content
      height calc(100% - 72px)
      padding 20px 0
      overflow hidden
      .line-block-items
        padding-bottom 20px
        .empty
          position absolute
          top 80px
          left calc(50% - 80px)
          height 20px
          padding-top 160px
          width 160px
          background url("icon_wantSee_empty@2x.png")no-repeat center top /124px 124px
          .text
            height 20px
            line-height 20px
            font-size 12px
            color #666666
        .item
          display flex
          height 102px
          background #171718
          margin-bottom 10px
          padding 9px 14px
          .img-wrapper
            flex 0 0 70px
            background url("bg_poster.png")no-repeat center/100% 100%
          .text-wrapper
            flex 1
            text-align left
            overflow hidden
            padding 15px 0 0 15px

            .name,.introduction,.protagonist
              overflow hidden
              text-overflow ellipsis
              white-space nowrap
            .name
              height 22px
              line-height 22px
              color #ffffff
              font-size 16px
            .introduction
              height 17px
              line-height 17px
              padding-top 8px
              color #ffffff
              font-size 12px
            .protagonist
              height 16px
              line-height 16px
              font-size 11px
              color #8B929E
              padding-top 8px
          .score-wrapper
            flex 0 0 75px
            position relative
            .score
              position absolute
              top 42px
              right 0px
              width 53px
              height 28px
              border-radius 14px
              border none
              background #EEAC21
              color #161719
              font-size 14px
              outline none
            &.evaluation
              background url("bg_evaluation.svg")no-repeat 25px 45px/50px 63px

</style>
